/**
 * 
 */
package jMiiEditor.mii.checker.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import jMiiEditor.mii.checker.MiiCheckerActionException;
import jMiiEditor.mii.checker.MiiCheckerFileObject;

/**
 * @author CC
 *
 */
public class MiiCheckerFileObjectDefaultImpl 
    implements MiiCheckerFileObject 
{
    private File file;
    
    public MiiCheckerFileObjectDefaultImpl( File aFile )
    {
        this.file = aFile;
    }
    
    @Override
    public String getDisplayPath()
    {
        return file.getPath();
    }

    @Override
    public Object getInternalObject()
    {
        return file;
    }
    
    @Override
    public OutputStream getOutputStream()  throws IOException
    {
        return new FileOutputStream( file );
    }

    @Override
    public MiiCheckerFileObject renameTo( String newFileName ) throws MiiCheckerActionException
    {
        File newFile = new File(this.file.getParentFile(), newFileName );

        boolean res = file.renameTo( newFile );
        
        if( !res ) {
            throw new MiiCheckerActionException("Can't rename [" + file + "] to [" + newFile + "]");
        }
        
        return new MiiCheckerFileObjectDefaultImpl( newFile );
    }

}
